home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94c.txt / 000006_icon-group-sender _Thu Dec 8 20:58:20 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  8KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 8 Dec 1994 14:01:17 MST
  2. To: icon-group-l@cs.arizona.edu
  3. Date: 8 Dec 1994 20:58:20 +0100
  4. From: antimiro@loria.fr (Valentin Antimirov)
  5. Message-Id: <3c7ogs$i9t@myrtille.loria.fr>
  6. Organization: CRIN & INRIA-Lorraine - Nancy - FRANCE
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <1994Dec7.221649.10939@cs.sfu.ca>, <3c62kb$pnu@caslon.CS.Arizona.EDU>
  9. Subject: Re: [Q] Algorithm for Regexp Subsumption
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12.  
  13. In article <3c62kb$pnu@caslon.CS.Arizona.EDU>, dave@CS.Arizona.EDU (Dave Schaumann) writes:
  14. |> 
  15. |> In article <1994Dec7.221649.10939@cs.sfu.ca>,
  16. |> Martin Vorbeck <vorbeck@cs.sfu.ca> wrote:
  17. |> 
  18. |> }  are there any algorithms out there for checking whether a regular
  19. |> }expression subsumes another one, ie L(E1) is a subset of L(E2)? I have a
  20. |> }"brute-force" solution along these lines:
  21. |> }
  22. |> }1. Compute equivalent finite automatas A1 (resp A2) for E1 (resp E2).
  23. |> }2. Compute A3 = A1 intersected with the complement of A2.
  24. |> }3. Test L(A3) = empty  ==>  E2 subsumes E1.
  25. |> }
  26. |> }But I wonder if this couldn't be done directly on the regular
  27. |> }expressions E1 and E2?
  28. |> 
  29. |> Another possibility would be to compute the minimized DFAs, then
  30. |> compute the minimized DFA of the union.  If it's the same as either
  31. |> of the originals, you've got a match.
  32. |> 
  33. |> Hard to say which method would be quicker.  Since they're essentially
  34. |> duals of each other, I wouldn't be surprised if it was a wash.
  35. |> 
  36. |> -Dave
  37.  
  38.  Yes, it is possible to prove any regular inequality E1 =< E2 (as well as
  39. any regular equation E1 = E2) in a pure algebraic way -- without
  40. constructing DFA's for the expressions involved.
  41.  
  42.  1.  As far as regular equations are concerned, such a way has been
  43. described in [1].  It is an algebraic calculus presented in the form
  44. of a term-rewriting system. I have written a program in OBJ3 (an
  45. algebraic programming language) implementing this calculus.  If
  46. someone is interested in getting the program (together with quite
  47. complete instructions how to run it, examples, etc.), send me please a
  48. request by e-mail.
  49.  
  50.  2.  Since E1 =< E2 is equivalent to E1 + E2 = E2, the abovementioned
  51. calculus can also be used for proving/disproving regular inequalities.
  52. However, there exists a more direct (and more efficient) algebraic
  53. procedure based on so-called "partial derivatives".  Below I outline it.
  54.  
  55.  Consider the set Reg of regular expressions on a given alphabet A:
  56.  
  57.   Reg ::= 0 | 1 | x | Reg . Reg | Reg + Reg | Reg *
  58.  
  59. where 0 denotes the empty language, 1 is a unit language, x is a letter
  60. from A, and the three other operations -- concatenation, regular union,
  61. and Kleene star -- have standard meaning.
  62.  
  63.  Let Reg0, Reg1 be subsets of Reg defined by the following grammars:
  64.  
  65.   Reg0 ::= 0 | x | Reg0 . Reg | Reg . Reg0 | Reg0 + Reg0
  66.  
  67.   Reg1 ::= 1 | Reg1 . Reg1 | Reg1 + Reg | Reg + Reg1 | Reg *
  68.  
  69. One can check that Reg is a disjoint union of Reg0 and Reg1 and that for
  70. any a0 \in Reg0 and a1 \in Reg1 the inequality 1 =< a0 is false and 1 =<
  71. a1 is true.) 
  72.  
  73.  Let Set[Reg] denote the set of all finite sets of reg.  expressions.
  74.  
  75. DEFINITION ( [3] ) 
  76.  Given x \in A, the function d_x : Reg -> Set[Reg], computing the set
  77. of partial derivatives of its argument w.r.t. x, is defined
  78. recursively by the following equations:
  79.  
  80.   d_x(0) = d_x(1) = {} (* an empty set *),
  81.   d_x(y) = if y == x then { 1 } else {} fi,
  82.   d_x(a+b) = d_x(a) \cup d_x(b),
  83.   d_x(a0.b) = d_x(a0).b,
  84.   d_x(a1.b) = d_x(a1).b \cup d_x(b),
  85.   d_x(a*) = d_x(a).a*
  86.  
  87. for all y\in A, a,b \in Reg, a0 \in Reg0, a1 \in Reg1.  Here the
  88. extension of concatenation _._ to Set[Reg] is defined in the following
  89. way:
  90.  
  91.   R . 0 = {}, 
  92.   {} . t = {},
  93.   {0} . t = {},
  94.   {1} . t = {t},
  95.   {a} . t = {a.t} if a =/= 0, a =/= 1,
  96.   (R \cup R').t = (R.t)\cup (R'.t)
  97.  
  98. for any R, R' \in Set[Reg], t \in Reg, t =/= 0, a\in Reg.
  99. --------------------
  100.  
  101.   Given a set R \in Set[Reg], let \sum R be either 0 if R={}, or a sum
  102. (regular union) a + b + ... of non-zero elements a, b, ... of R. Note
  103. that here the regular union _+_ is considered to be associative,
  104. commutative and idempotent (while in the above definition of d_x() all
  105. regular expressions are treated as free terms).
  106.  
  107.  
  108. DEFINITION ( [2] ) Given a, b \in Reg, x\in A, and p \in d_x(a), the
  109. inequality p =< \sum d_x(b) is called a "partial derivative of a regular
  110. inequality a =< b w.r.t. the letter x".
  111.   Let pd_x(a =< b) be the set of all partial derivatives of a =< b w.r.t.
  112. x.  Given a set S of inequalities, let pd_x(S)=\bigcup_{s\in S}pd_x(s).
  113. ------------------
  114.  
  115.  Iterating this definition, one obtains partial derivatives of a =< b
  116. w.r.t. non-empty words on A:
  117.  
  118.     pd_{wx}(a =< b) =  pd_x(pd_w(a =< b)).
  119.  
  120. for all w\in A^+, x \in A.
  121.  
  122.  
  123. THEOREM ( [2] ) 
  124.  1.  The set 
  125.  
  126.     PD(a=<b) = \bigcup_{w\in A^+} pd_w(a =< b) 
  127.  
  128. of all possible partial derivatives of a =< b w.r.t. all non-empty words
  129. on A is finite and its cardinality is less than or equal to
  130. \let(a)*2^\let(b) where \let(r) is the number of occurrences of alphabet
  131. letters appearing in the reg.  expression r.
  132.  
  133.  2. If a =< b is a valid inequality (i.e., the regular language denoted by
  134. a is a subset of one denoted by b), then all its partial derivatives are
  135. also valid. If a =< b is not valid, then the set PD(a =< b) contains at
  136. least one "trivially inconsistent" inequality of the form p1 =< q0 where
  137. p1\in Reg1, q0\in Reg0.  
  138. ------------------
  139.  
  140.  
  141.  This gives the following procedure to decide whether a regular
  142. inequality a=<b is valid:
  143.  
  144.  1. Check if a=<b is "trivially inconsistent", i.e. if a\in Reg1, b\in
  145. Reg0 -- then a=<b = false. 
  146.  
  147.  2. Otherwise, compute the set pd_x(a =< b) for all the letters x
  148. occuring in a. If one of the new inequalities is "trivially
  149. inconsistent", then a=<b is disproved. Otherwise, keep computing partial
  150. derivatives of new inequalities until either you get a "trivially
  151. inconsistent" inequality, or the set of inequalities becomes saturated
  152. (no new partial derivative can be obtained). In the latter case, a=<b is
  153. valid -- as well as all the obtained partial derivatives of a=<b.
  154.  
  155. (See [3] for a natural way to compute partial derivatives through
  156. so-called non-deterministic linear forms).
  157.  
  158.  
  159.  This is indeed a decision procedure, but its efficiency can be
  160. drastically improved using simple "logical" observations. First, it's
  161. quite clear that it makes no sense to differentiate inequalities like
  162.  
  163.          a =< a, a =< a + b, 0 =< a, 1 =< a1 
  164.  
  165. etc. which are "trivial tautologies". These should just be removed from
  166. the set of inequalities to be checked. Second, if two inequalities of the
  167. form a =< b and a =< b + c occurs in the set, then the second one can
  168. also be removed, since it is a logical consequence of the first one.
  169.  
  170.  It is proved in [2] that with these optimizations the procedure in some
  171. cases is *EXPONENTIALLY* faster that any one constructing DFA for the
  172. expressions involved -- you can check it yourself on the following
  173. example:
  174.  
  175.    (a* b)* (a a ... a) a *  =< (a + b)* a (a+b)...(a+b)
  176.             ^-------^                     ^------------^
  177.              n times                        n-1 times 
  178.  
  179. (it is known that the minimal DFA for the right-hand side has 2^n
  180. states, but our procedure -- with the optimizations described above --
  181. generates only n+2 partial derivatives to be checked).
  182.  
  183.  
  184.  REFERENCES
  185.  
  186. [1] V.~M. Antimirov and P.~D. Mosses.  Rewriting extended regular
  187. expressions.  {\em Theoretical Comput. Sci.}, 141, 1995.  (To appear.
  188. Available on WWW-page http://www.daimi.aau.dk/~pdm/rere.ps.Z).
  189.  
  190. [2] V.~M. Antimirov.  Partial derivatives of regular expressions and
  191. finite automata constructions. (To be presented at STACS'95.  Available
  192. as tech. report CRIN-94-245).
  193.  
  194. [3] V.~M. Antimirov.  Rewriting regular inequalities, October 1994.
  195. (Submitted)
  196.  
  197. _______________________________________________________________________________
  198.  Valentin ANTIMIROV                     | Tel.:  (33) 83 59 30 15 (direct)
  199.  CRIN (CNRS) & INRIA-Lorraine,          |        (33) 83 59 30 00 (INRIA)
  200.  615, rue du Jardin Botanique, B.P. 101 | Fax:   (33) 83 27 83 19
  201.  F54602  VILLERS-LES-NANCY Cedex,       | Telex:  850 238 F
  202.  FRANCE                                 | e-mail: Valentin.Antimirov@loria.fr
  203. -------------------------------------------------------------------------------
  204.